package Logic

import (
	"fmt"

	"yz-go/Interface"

	"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
	"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"
	ocr "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ocr/v20181119"
)

type GeneralBasic struct{}

// 用这个节哦固体来实现 接口

func (g *GeneralBasic) TXOCR(input *map[string]string) (any, error) {

	client := Interface.TXOCRClient()

	// 实例化一个请求对象,每个接口都会对应一个request对象
	request := ocr.NewGeneralBasicOCRRequest()

	// 检查映射中是否存在指定的键
	if val, ok := (*input)["imageBase"]; ok {
		// 如果键存在，则将值赋给一个变量
		imageBase := val
		request.ImageBase64 = &imageBase // 和url 二者选其一，若俩个都有 默认url

	} else {
		request.ImageUrl = common.StringPtr((*input)["imageUrl"])
	}

	fmt.Printf("bas64: %v", request.ImageBase64)
	fmt.Printf("url: %v", request.ImageUrl)

	request.Scene = common.StringPtr("123")
	request.LanguageType = common.StringPtr("zh")
	request.IsPdf = common.BoolPtr(false)
	request.PdfPageNumber = common.Uint64Ptr(0)
	request.IsWords = common.BoolPtr(false)

	// 返回的resp是一个GeneralBasicOCRResponse的实例，与请求对象对应
	response, err := client.GeneralBasicOCR(request)
	if _, ok := err.(*errors.TencentCloudSDKError); ok {
		fmt.Printf("An API error has returned: %s", err)
		return "An API error has returned", err
	}

	if err != nil {
		panic(err)
	}

	// 输出json格式的字符串回包
	fmt.Printf("%s", response.ToJsonString())

	return response, nil
	// return Common.ResData{Common.SUCCESS, "", response}
}
